package com.yangfei.mystudy1020.OGL20.utils;

import android.content.Context;
import android.content.res.Resources;

import com.bumptech.glide.load.engine.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by yangfei on 2017/12/12.
 */

public class TextResourceReader {
    public static String readTextFileFromResouce(Context context,int resourceId){
        StringBuilder body = new StringBuilder();
        try{
            InputStream inputStream = context.getResources().openRawResource(resourceId);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);

            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

            String nextLine;
            while ((nextLine = bufferedReader.readLine())!=null){
                body.append(nextLine);
                body.append('\n');
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Resources.NotFoundException e){
            e.printStackTrace();
        }

        return body.toString();
    }
}
